//
//  Qb_FriendViewController.m
//  Cd_Qb
//
//  Created by mac on 2018/3/14.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "Qb_FriendViewController.h"
#import "Qb_FrienddetailsViewController.h"

#import "Qb_FriendTableViewCell.h"
#import "Qb_FriendHeadView.h"
@interface Qb_FriendViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) Qb_FriendHeadView* head;
@property (nonatomic,strong) UITableView *FriendtableView;
@property (nonatomic,strong) NSMutableArray *FriendDateSource;
@end

@implementation Qb_FriendViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.title = @"我的伙伴";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.FriendtableView];
}

#pragma mark --UITableViewDelegate&&UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.FriendDateSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Qb_FriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell loadData:self.FriendDateSource[indexPath.row]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80*AdaptiveScale_W;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44*AdaptiveScale_W;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 44*AdaptiveScale_W)];
    label.text = @"     客户明细";
    label.textAlignment = NSTextAlignmentLeft;
    label.font = AdFont(17);
    return label;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Qb_FrienddetailsViewController *vc =  [Qb_FrienddetailsViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}


-(UITableView *)FriendtableView{
    if (!_FriendtableView) {
        _FriendtableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _FriendtableView.delegate = self;
        _FriendtableView.dataSource = self;
        _head = loadNibNamed(@"Qb_FriendHeadView").lastObject;
//        _head.delegate = self;
        CGRect frame = _head.frame;
        frame.size.height = frame.size.height*AdaptiveScale_W;
        _head.frame = frame;
        _FriendtableView.tableHeaderView = _head;
        _FriendtableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
        _FriendtableView.showsVerticalScrollIndicator = NO;
//        _FriendtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_FriendtableView registerNib:[UINib nibWithNibName:@"Qb_FriendTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
        //        WS(weakself);
        //        _JointableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [weakself loadNewData];
        //        } ];
        //
        //        _JointableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        //            //刷新时候，需要执行的代码。一般是请求更多数据，请求成功之后，刷新列表
        //            [weakself loadMoreData];
        //        }];
    }
    return _FriendtableView;
}


-(NSMutableArray *)FriendDateSource{
    if (!_FriendDateSource) {
        _FriendDateSource = [NSMutableArray array];
        NSArray *imgary = @[@"Qb_FriendCellImg01",@"Qb_FriendCellImg02",@"Qb_FriendCellImg03",@"Qb_FriendCellImg04"];
        NSArray *nameary = @[@"普通会员",@"黄金会员",@"白金会员",@"钻石会员"];
        for (int i = 0; i<imgary.count; i++) {
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:imgary[i] forKey:@"img"];
            [dic setValue:nameary[i] forKey:@"name"];
            [_FriendDateSource addObject:dic];
        }
    }
    return _FriendDateSource;
}

@end
